//goodpylon.txt - A friendly pylon. Will help out character, if the right flag has 
// been set to activate it.
//Cell 0,1 - Stuff done flag. If both 0, nothing. Otherwise If zero, this 
//pylon wont attack. If the pylon is itself attacked, will set the not-attack setting back to 0.
// Cell 2 - If nonzero, this pylon can use extra-powerful attacks.

begincreaturescript;

short i,target;
short last_abil;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE; 
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if ((get_memory_cell(0) != 0) || (get_memory_cell(1) != 0)) {
		if (get_flag(get_memory_cell(0),get_memory_cell(1)) == 0) {
			if (get_attitude(ME) < 4) {
				pc_heard_sound(166);
				print_str_color("A pylon powers down.",2);
				set_attitude(ME,4);
				}
				
			end();
			}
		}
		
	if ((get_memory_cell(0) != 0) || (get_memory_cell(1) != 0)) {
		if (get_flag(get_memory_cell(0),get_memory_cell(1)) > 0) {
			if ((get_nearest_good_char(6) >= 0) && (get_attitude(ME) == 4)) {
				pc_heard_sound(167);
				print_str_color("When you get close to the pylon, it charges itself up.",2);
				run_sparkles_on_char(ME,8,5,1);							
				set_attitude(ME,3);
				}
				else if ((get_nearest_good_char(6) < 0) && (get_attitude(ME) < 4)) {
					pc_heard_sound(166);
					print_str_color("A pylon powers down.",2);
					set_attitude(ME,4);
					}
			}
		}
		
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if ((get_memory_cell(0) != 0) || (get_memory_cell(1) != 0)) {
		if (get_flag(get_memory_cell(0),get_memory_cell(1)) == 0) {
			if (get_attitude(ME) < 4) {
				pc_heard_sound(166);
				print_str_color("A pylon powers down.",2);
				set_attitude(ME,4);
				}
			set_foe_target(ME,-1);
			set_state(START_STATE);
			}
		}
	if ((get_attitude(ME) < 4) && (get_nearest_good_char(6) < 0)) {
			pc_heard_sound(166);
			print_str_color("A pylon powers down.",2);
			set_attitude(ME,4);
			set_foe_target(ME,-1);
			set_state(START_STATE);
			}
		
	if (target_ok() == FALSE)
		set_state(START_STATE);
		
	if ((get_memory_cell(2) > 0) && 
	  (get_ran(1,0,100) < 50) && (tick_difference(last_abil,get_current_tick()) > 0)) {
		print_named_str(ME,"fires a beam of energy.");
		pc_heard_sound_delay(131,250);						
		run_sparkles_on_char(get_target(),6,8,1);
		run_sparkles_on_char(ME,6,8,1);
		
		if (get_ran(1,0,100) < 50)
			set_char_status(get_target(),1,-5);
			else if (get_ran(1,0,100) < 50)
				set_char_status(get_target(),0,-4);
				else set_char_status(get_target(),7,4);
		last_abil = get_current_tick();
		}
		
	do_attack();
	turret_heal();
break;

beginstate TALKING_STATE;
	print_str("Talking: The pylon is a simple organism in a crystal shell. It can't talk.");
	if ((get_memory_cell(0) != 0) || (get_memory_cell(1) != 0)) {
		if (get_flag(get_memory_cell(0),get_memory_cell(1)) == 0) 
			print_str("  It is not currently receiving power.");
			else print_str("  It is currently receiving power.");
		}
break;